using System;

using Gtk;

namespace repragator
{
	public partial class Editor : Gtk.Dialog
	{
		public string Text
		{
			get
			{
				return this.textView.Buffer.Text;
			}
			set
			{
				this.textView.Buffer.Text = value;
			}
		}
		
		public new string Title
		{
			get
			{
				return this.titleEntry.Text;
			}
			set
			{
				if (!this.Macro)
					this.titleEntry.IsEditable = false;
				
				this.titleEntry.Text = value;
			}
		}
		
		public bool Macro
		{	
			get;
			set;
		}
		
		public Editor ()
		{
			this.Build ();
		}
		
		public Editor(bool macro)
			: this()
		{
			this.Macro = macro;	
		}
		
		protected void OnSaveButtonClicked (object sender, System.EventArgs e)
		{
			if (this.Macro && this.titleEntry.Text == string.Empty)
			{
				MessageDialog message = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Enter a name for your macro.");
				
				if (message.Run() != (int)ResponseType.Yes)
				{
					message.Destroy();
					
					return;
				}
				
				message.Destroy();
			}
			
			this.Respond(Gtk.ResponseType.Accept);
			
			this.HideAll();
		}
		
		protected void OnCancelButtonClicked (object sender, System.EventArgs e)
		{
			this.Respond(Gtk.ResponseType.Cancel);
			
			this.Destroy();
		}
	}
}

